// JavaScript Document

$(function(){
		   
	/**获取候选人组并添加到td中去**/
	$("#addCandidate").click(function(){
		$("#candidate_td_span").html("");
		$("input[name=candidate_checkbox]:checked").each(function(){
			var checkboxVal = $(this).val();
			var selectedCon = $(this).parent().parent(".selected_tr").children().last().text();
			$("#candidate_td_span").append("<span>"+selectedCon+"</span><span>&nbsp;&nbsp;&nbsp;</span>");
			$("#candidate_td_span").append("<input type=\"hidden\" name=\"candidate_group[]\" value=\""+checkboxVal+"\" \/>");
		});
		$("#BgDiv").css("display","none");
	    $(".showlist").css("display", "none");
	});
	
	/**获取投票人组并添加到td中去**/
	$("#addVoter").click(function(){
		$("#voter_td_span").html("");
		$("input[name=voter_checkbox]:checked").each(function(){
			var checkboxVal = $(this).val();
			var selectedCon = $(this).parent().parent(".selected_tr").children().last().text();
			$("#voter_td_span").append("<span>"+selectedCon+"</span><span>&nbsp;&nbsp;&nbsp;</span>");
			$("#voter_td_span").append("<input type=\"hidden\" name=\"voter_group[]\" value=\""+checkboxVal+"\" \/>");
		});
		$("#BgDiv").css("display","none");
	    $(".showlist").css("display", "none");
	});
	
	/**获取ip分组并添加到td中去**/
	$("#addIp").click(function(){
		$("#voter_td_span").html("");
		$("input[name=ip_checkbox]:checked").each(function(){
			var checkboxVal = $(this).val();
			var selectedCon = $(this).parent().parent(".selected_tr").children().last().text();
			$("#ip_td_span").append("<span>"+selectedCon+"</span><span>&nbsp;&nbsp;&nbsp;</span>");
			$("#ip_td_span").append("<input type=\"hidden\" name=\"ip_group[]\" value=\""+checkboxVal+"\" \/>");
		});
		$("#BgDiv").css("display","none");
	    $(".showlist").css("display", "none");
	});
	
	/**ip类型选择**/
	$(".setip").change(function(){
		var select_val = $(this).find("option:selected").val();
		switch(select_val){
			case "no_limit":$("#ip_td #ip").css("display","none");break;
			case "permit":$("#ip_td #ip").css("display","inline").attr("alt","permit");break;
			case "ban":$("#ip_td #ip").css("display","inline").attr("alt","ban");break;
		}
		$("#ip_td_span").html("");
		$("input[name=ip_checkbox]:checked").each(function(){this.checked = ""});
	});
})